package com.hanzidong.cms.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hanzidong.cms.dao.ArticleMapper;
import com.hanzidong.cms.entity.Article;
import com.hanzidong.cms.entity.User;
import com.hanzidong.cms.service.ArticleService;

@Service
public class ArticleServiceImpl implements ArticleService{

	@Resource
	private ArticleMapper articleMapper;

	@Override
	public boolean add(Article article) {
		return articleMapper.add(article);
	}

	@Override
	public PageInfo<Article> articles(Integer pageNum, Integer pageSize,User user) {
		//设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Article> list = articleMapper.articles(user);
		
		return new PageInfo<Article>(list);
	}

	@Override
	public Article getArticleById(Integer id) {
		return articleMapper.getArticleById(id);
	}

	@Override
	public PageInfo<Article> list(Integer pageNum, Integer pageSize, Article article) {
		//设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Article> list = articleMapper.list(article);
		
		
		return new PageInfo<Article>(list);
	}

	/**
	 * 根据id修改文章状态
	 */
	@Override
	public boolean updateArticle(Article article) {
		
		return articleMapper.updateArticle(article);
	}

	@Override
	public PageInfo<Article> listByHit(Integer pageNum, Integer pageSize, Article article) {
		//设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		
		//查询数据
		List<Article> list = articleMapper.listByHit(article);
		
		
		return new PageInfo<Article>(list);
	}
	
}
